#include "EntryBlock.h"
#include "Translation.h"
#include <QXmlStreamWriter>

EntryBlock::~EntryBlock()
{
	QHashIterator<QString, Translation*> it(_translations);
	while (it.hasNext()) {
		it.next();
		delete it.value();
	}
}

void EntryBlock::dump(QXmlStreamWriter& writer)
{
	// Cada entrada es un elemento de una lista
	writer.writeStartElement("li");
	writer.writeAttribute("class", "listItem");
	// Escribimos el término original
	if (_translations.contains("OriginalTerm")) {
		_translations.value("OriginalTerm")->dump(writer);
	}
	// Escribimos las distintas traducciones devueltas
	if (_translations.contains("FirstTranslation")) {
		_translations.value("FirstTranslation")->dump(writer);
	}
	if (_translations.contains("SecondTranslation")) {
		writer.writeCharacters(", ");
		_translations.value("SecondTranslation")->dump(writer);
	}
	if (_translations.contains("ThirdTranslation")) {
		writer.writeCharacters(", ");
		_translations.value("ThirdTranslation")->dump(writer);
	}
	if (_translations.contains("FourthTranslation")) {
		writer.writeCharacters(", ");
		_translations.value("FourthTranslation")->dump(writer);
	}
	// Escribimos la nota si la hay
	if (!_note.isEmpty()) {
		writer.writeCharacters(QString(" <NOTA: %1>").arg(_note));
	}
	writer.writeEndElement(); // li
}

